﻿namespace AC.ExtendedRenderer.Toolkit
{
    using AC.ExtendedRenderer.Toolkit.Utils;
    using System;
    using System.ComponentModel;
    using System.Drawing;
    using System.Runtime.CompilerServices;
    using System.Windows.Forms;
    using System.Windows.Forms.Design;

    [DefaultEvent("ValueChanged"), ToolStripItemDesignerAvailability(ToolStripItemDesignerAvailability.StatusStrip | ToolStripItemDesignerAvailability.ToolStrip)]
    public class KryptonSliderBar : ToolStripControlHostFixed
    {
        private IContainer components;

        public event ValueChangedEventHandler ValueChanged;

        public KryptonSliderBar() : base(new KryptonSlider())
        {
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing && (this.components != null))
            {
                this.components.Dispose();
            }
            base.Dispose(disposing);
        }

        private void InitializeComponent()
        {
            this.components = new Container();
        }

        private void kminus_SliderButtonFire(KryptonSliderButton Sender, EventArgs e)
        {
        }

        private void kplus_SliderButtonFire(KryptonSliderButton Sender, EventArgs e)
        {
        }

        protected override void OnSubscribeControlEvents(Control c)
        {
            base.OnSubscribeControlEvents(c);
            (base.Control as KryptonSlider).ValueChanged += new KryptonSlider.ValueChangedEventHandler(this.OnValueChanged);
            (base.Control as KryptonSlider).kminus.SliderButtonFire += new KryptonSliderButton.SliderButtonFireEventHandler(this.kminus_SliderButtonFire);
            (base.Control as KryptonSlider).kplus.SliderButtonFire += new KryptonSliderButton.SliderButtonFireEventHandler(this.kplus_SliderButtonFire);
        }

        protected override void OnUnsubscribeControlEvents(Control c)
        {
            base.OnUnsubscribeControlEvents(c);
            (base.Control as KryptonSlider).ValueChanged -= new KryptonSlider.ValueChangedEventHandler(this.OnValueChanged);
            (base.Control as KryptonSlider).kminus.SliderButtonFire -= new KryptonSliderButton.SliderButtonFireEventHandler(this.kminus_SliderButtonFire);
            (base.Control as KryptonSlider).kplus.SliderButtonFire -= new KryptonSliderButton.SliderButtonFireEventHandler(this.kplus_SliderButtonFire);
        }

        private void OnValueChanged(KryptonSlider Sender, KryptonSlider.SliderEventArgs e)
        {
            if (this.ValueChanged != null)
            {
                this.ValueChanged(Sender, e);
            }
        }

        [Category("Slider Values"), DefaultValue(typeof(int), "200")]
        public int FireInterval
        {
            get
            {
                return (base.Control as KryptonSlider).FireInterval;
            }
            set
            {
                (base.Control as KryptonSlider).FireInterval = value;
            }
        }

        [Category("Slider Values")]
        public int Maximum
        {
            get
            {
                return (base.Control as KryptonSlider).Maximum;
            }
        }

        [Category("Slider Values")]
        public int Minimum
        {
            get
            {
                return (base.Control as KryptonSlider).Minimum;
            }
        }

        [DefaultValue(100), Category("Slider Values")]
        public int Range
        {
            get
            {
                return (base.Control as KryptonSlider).Range;
            }
            set
            {
                (base.Control as KryptonSlider).Range = value;
            }
        }

        [Category("Slider Values"), DefaultValue(typeof(bool), "false")]
        public bool SingleClick
        {
            get
            {
                return (base.Control as KryptonSlider).SingleClick;
            }
            set
            {
                (base.Control as KryptonSlider).SingleClick = value;
            }
        }

        [DefaultValue(5), Category("Slider Values")]
        public int Steps
        {
            get
            {
                return (base.Control as KryptonSlider).Steps;
            }
            set
            {
                (base.Control as KryptonSlider).Steps = value;
            }
        }

        [Category("Control")]
        public KryptonSlider Tracker
        {
            get
            {
                return (base.Control as KryptonSlider);
            }
        }

        [Category("Slider Values"), DefaultValue(typeof(Size), "140, 16")]
        public Size TrackerSize
        {
            get
            {
                return (base.Control as KryptonSlider).Size;
            }
            set
            {
                (base.Control as KryptonSlider).Size = value;
            }
        }

        [Category("Slider Values"), DefaultValue(0)]
        public int Value
        {
            get
            {
                return (base.Control as KryptonSlider).Value;
            }
            set
            {
                (base.Control as KryptonSlider).Value = value;
            }
        }

        public delegate void ValueChangedEventHandler(KryptonSlider Sender, KryptonSlider.SliderEventArgs e);
    }
}

